<template>
	<view class="select-shop-card" v-for="(item,index) in ShopDatas" :key="item.shop_id">
		<view class="Shop-Card" @click="toShopDetail(item.shop_id)">
			<image class="coverImage" :src="imageUrl+item.cover_image" mode="aspectFill"></image>
			<view class="right-shop-info">
				<view class="title">{{item.title}} · {{item.subtitle}}</view>
				<view class="descriptive">{{item.description}}</view>
			</view>
		</view>
		<radio-group @change="shopHandleChange" class="radio">
			<view class="radio-item">
				<radio :value="item.shop_id" :checked="shopId == item.shop_id"  class="radio-button" color="#000"></radio>
			</view>
		</radio-group>
	</view>
</template>

<script setup>
	import { imageUrl } from '@/config/request/request';
	import { routerGuard } from '@/config/RouteGuard.js'
	import { ref, defineProps, defineEmits, watchEffect } from 'vue';
	const propos = defineProps({
		ShopDatas:{
			type:Array,
			default:()=>[]
		}
	})
	const shopId = ref()
	const emit = defineEmits();
	watchEffect(()=>{
		console.log('父组件传过来的绑定Shop数据',propos.ShopDatas);
	})
	const toShopDetail = (shopId) => {
		console.log('商品id', shopId)
		const url = `/homeSubpages/ProductDetails/index?ShopId=${shopId}`;
		routerGuard(url);
	}
	// 选择的环线商品
	const shopHandleChange = (e) => {
		shopId.value = e.detail.value;
		console.log("选择环线商品ID：", shopId.value);
		// 通过emit将选中的shopId传递给父组件
		emit('shopSelected', shopId.value);
	};
</script>

<style scoped lang="scss">
	.select-shop-card{
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.Shop-Card{
			width: 80%;
			height: 160rpx;
			display: flex;
			align-items: center;
			gap: 20rpx;
			padding: 20rpx;
			box-sizing: border-box;
			border-radius: 20rpx;
			border: 2rpx solid #e6e6e6;
			box-shadow: 0rpx 2rpx 3rpx 0rpx rgba(209, 209, 209, 0.2);
			.coverImage{
				width: 160rpx;
				height: 100%;
				border-radius: 10rpx;
			}
			.right-shop-info{
				max-height: 100%;
				min-height: 100%;
				max-width: calc(100% - 200rpx);
				min-width: calc(100% - 200rpx);
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				.title{
					font-size: 26rpx;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1; /* 设置最大行数 */
					overflow: hidden;
					text-overflow: ellipsis;
					line-height: 1.5em; /* 每行的高度 */
					word-break: break-all; /* 防止长单词导致布局破坏 */
				}
				.descriptive{
					font-size: 24rpx;
					color: #8f8f8f;
					font-family: 200;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2; /* 设置最大行数 */
					overflow: hidden;
					text-overflow: ellipsis;
					word-break: break-all; /* 防止长单词导致布局破坏 */
				}
				.footer-prices-views{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.prices{
						font-size: 26rpx;
					}
					.views{
						font-size: 24rpx;
						color: #8f8f8f;
					}
				}
			}
		}
		.radio{
			width: 50rpx;
			.radio-item {
				.radio-button {
					transform:scale(0.9)
				}
			}
		}	
	}
</style>